package program;

import kernel.exception.OSException;
import kernel.process.AbstractProcess;
import kernel.process.AbstractProcessHeader;

/**
 * Echo process.
 * For more see man() method.
 * @author Petr Hajek, Veronika Vencurikova
 *
 */
public class Echo extends AbstractProcess {

	public Echo(AbstractProcessHeader header, long pid) {
		super(header, pid);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String doJob(String input) throws OSException {
		String out = "" + input;
		for (int i = 0; i < this.params.size() - 1; i++) {
			out += this.params.get(i) + " ";
		}
		out += this.params.get(this.params.size() - 1);
		return out;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean needParams() {
		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void kill() throws OSException {
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String continueJob() throws OSException {
		this.shouldEnd = true;
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected String finalizeJob() throws OSException {
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String man(String command) {
	String man = "";
			
			man += "    displays a line of text\n";
			man += "\n";
			man += "Command syntax:\n";
			man += "    echo [STRING] ...\n";
			man += "\n";
			man += "Examples:\n";
			man += "    echo Hello world!\n";
		
			return man;
	}

}
